package com.example.tanloadpic;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;

import java.io.ByteArrayInputStream;

public class TanPicCompressConfig implements RequestCreator.CompressConfig {

    private final int mMaxByteCount;

    public TanPicCompressConfig(int maxByteCount) {
        this.mMaxByteCount = maxByteCount;
    }

    @Override
    public Bitmap Compress(Bitmap bitmap) {
        Matrix matrix = new Matrix();
        matrix.setScale(0.5f, 0.5f);
        int byteCount = bitmap.getByteCount();
        while (byteCount > mMaxByteCount) {
            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            byteCount = bitmap.getByteCount();
        }
        return bitmap;
    }


}
